//
//  LLT_LiveViewController_LXH.m
//  CoderLLT
//
//  Created by 刘晓萌 on 15/12/17.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LLT_LiveViewController_LXH.h"

@interface LLT_LiveViewController_LXH ()<UIWebViewDelegate>

@property (weak, nonatomic) IBOutlet UIWebView *liveWebview;

@end

@implementation LLT_LiveViewController_LXH

- (void)viewDidLoad {
    [super viewDidLoad];
    self.liveWebview.delegate = self;
    [self makeWebView];
}

//
//-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
//    return YES;
//}
-(BOOL)shouldAutorotate {
    return YES;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
-(void)makeWebView{
   NSString *webHtmlStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:self.url] encoding:NSUTF8StringEncoding error:nil];
    NSMutableString *htmlStr = [NSMutableString new];
    NSString *inBodyHtml = [self subHTML:@" <div class=\"video0\">" andEndStr:@"<div class=\"video-loading\"></div>" andFullHtml:webHtmlStr];
    NSString *hstr1 = [self subHTML:@"<html>" andEndStr:@"<body>" andFullHtml:webHtmlStr];
    NSString *hstr2 = [self subHTML:@"</body>" andEndStr:@"</html>" andFullHtml:webHtmlStr];
    [htmlStr appendString:@"<html>"];
    [htmlStr appendString:hstr1];
    [htmlStr appendString:@"<body>"];
    [htmlStr appendString:inBodyHtml];
    [htmlStr appendString:@"</body>"];
    [htmlStr appendString:hstr2];
    [htmlStr appendString:@"</html>"];
    [self.liveWebview loadHTMLString:htmlStr baseURL:[NSURL URLWithString:self.url]];
}


-(NSString *)subHTML:(NSString *)startStr andEndStr:(NSString *)endStr andFullHtml:(NSString *)fullHtML{
    
    NSRange rang1=[fullHtML rangeOfString:startStr];
    NSMutableString *webHtmlStr2=[[NSMutableString alloc]initWithString:[fullHtML substringFromIndex:rang1.location+rang1.length]];
    NSRange rang2=[webHtmlStr2 rangeOfString:endStr];
    NSMutableString *webHtmlStr3=[[NSMutableString alloc]initWithString:[webHtmlStr2 substringToIndex:rang2.location]];
    return webHtmlStr3;

}
/**
 *  返回上个页面
 *
 *  @param sender
 */
- (IBAction)didClickLeftBackButton:(UIButton *)sender {
    DissMissBack;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
